#include "CG_str_hash.h"


CG_str_hash::CG_str_hash()
{
}


CG_str_hash::~CG_str_hash()
{
	this->my_hash_map.clear();
}


bool CG_str_hash::CG_ff_hash_insert(CG_flip_flop& ff)
{
	std::pair<ff_hash_map_type::iterator, bool> res;
	CG_flip_flop *temp_ff;
	
	try
	{
		temp_ff = new CG_flip_flop(ff);
	}
	catch(std::bad_alloc e)
	{
		std::clog << "CG_ff_hash_insert: bad memory allocation" << endl;
		return false;
	}

	if(this->my_hash_map.size() >= this->my_hash_map.max_size())
	{
		return false;
	}

	this->my_hash_map[ff.get_name()] = *temp_ff;

	return true;
}


long CG_str_hash::CG_str_hash_get_size()
{
	return this->my_hash_map.size();
}


CG_flip_flop &CG_str_hash::CG_str_hash_get(const char *ff_name)
{
	return this->my_hash_map[string(ff_name)];
}


bool CG_str_hash::CG_str_hash_erase(const char *ff_name)
{
	if(NULL == ff_name)
	{
		return false;
	}

	this->my_hash_map.erase(ff_name);
	return true;
}